﻿using cuiail.DBModels;
using Dapper;

namespace cuiail.DBConnections
{
    public interface IWorkingModeService
    {
        Task<IEnumerable<WorkingMode>> GetAllWorkingModesAsync();
    }

    public class WorkingModeService : IWorkingModeService
    {
        private readonly IDbConnectionFactory _connectionFactory;

        public WorkingModeService(IDbConnectionFactory connectionFactory)
        {
            _connectionFactory = connectionFactory;
        }

        public async Task<IEnumerable<WorkingMode>> GetAllWorkingModesAsync()
        {
            using var connection = _connectionFactory.CreateConnection();
            const string sql = "SELECT WorkingModeId, WorkingModeName, InsertTime FROM WorkingMode";
            return await connection.QueryAsync<WorkingMode>(sql);
        }
    }

}
